package cn.tannn.ops.sys.domain;

import cn.tannn.ops.nginx.service.DomainsService;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

/**
 *
 * 定时任务里的一些通用配置
 *
 * @author <a href="https://t.tannn.cn/">tan</a>
 * @version V1.0
 * @date 2024/12/10 10:52
 */
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "定时任务里的一些通用配置")
public class WorkerConfig {

    /**
     * 域名证书过期通知时间设置
     * <p> use {@link DomainsService#findsWebHookDomains(Integer)}</p>
     */
    @Schema(description = "域名证书过期通知时间设置/天")
    Integer domainSslExpiryDay;

    public Integer getDomainSslExpiryDay() {
        return domainSslExpiryDay==null||domainSslExpiryDay<1?10:domainSslExpiryDay;
    }

    /**
     * init
     */
    public static WorkerConfig initWorker() {
        WorkerConfig worker = new WorkerConfig();
        worker.setDomainSslExpiryDay(10);
        return worker;
    }

    /**
     * init
     */
    public static JSONObject initWorkerConfigJson() {
        return WorkerConfig.initWorker().toJson();
    }

    public JSONObject toJson() {
        return JSONObject.from(this);
    }
}
